/*
 * @Description:
 * @Author: mmzhang
 * @Date: 2021-12-15 17:16:05
 * @LastEditTime: 2023-01-12 14:30:15
 */
import Opt from '@/components/dt/info/Opt.js'
import subMgr from '@/biz/sales/subOrder.js'
import dateOpt from '@/biz/option/date.js'
import ruleOpt from '@/biz/option/rule.js'
import houseOpt from '@/biz/option/house.js'
import tool from '@/common/tool.js'
import nameOpt from '@/biz/option/name.js'
import caseMgr from '@/biz/crimeSceneList'

let _this = null
class SearchOpt extends Opt {
  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let pushUserList = []

    function getPushName(query) {
      return caseMgr.getBuildingUserList({ name: query }).then((res) => {
        pushUserList = res || []
        return pushUserList
      })
    }

    let cityAttrSort = []

    this.all = [
      // [houseOpt.create({
      //   key: 'buildingId',
      //   rules:[],
      //   to: (info) => {
      //     return {
      //       buildingId: info.housesId,
      //       companyId: info.companyId,
      //       housesName: info.housesName
      //     }
      //   }
      // }),
      [
        {
          title: '案场名称',
          key: 'housesName',
          placeholder: '请输入案场名称',
          input: {}
        },
        {
          title: '案场人员',
          key: 'salesManager',
          placeholder: '请输入案场人员姓名',
          select: {
            clearable: true,
            filterable: true,
            options: pushUserList.length > 0 ? pushUserList : [],
            remote: (key) => {
              return getPushName(key)
            }
          }
        },
        {
          key: 'cityId',
          title: '所属城市',
          load: (o) => {
            let params = {
              level: 2,
              page: '1',
              parentCode: '',
              rows: '100'
            }
            caseMgr.getAreacodePropertyList(params).then((res) => {
              res.list.map((item) => {
                item.value = item.cityCode
                item.label = item.cityName
                item.loading = false
                item.children = []
              })
              o.cascader.options = res.list
              cityAttrSort = res.list
            })
          },
          cascader: {
            options: cityAttrSort,
            loadData(item, callback) {
              item.loading = true
              let params = {
                level: 3,
                page: '1',
                parentCode: item.value,
                rows: '100'
              }
              caseMgr.getAreacodePropertyList(params).then((res) => {
                res.list.map((itemL) => {
                  itemL.value = itemL.cityCode
                  itemL.label = itemL.cityName
                  item.children.push(itemL)
                })

                item.loading = false
                callback()
              })
            }
          }
        }
      ],
      [
        {
          col: 8,
          title: '案场状态',
          key: 'status',
          placeholder: '请选择',
          select: {
            key: 'buildStatus'
          }
        },
        {
          col: 8,
          title: '合作模式',
          key: 'cooperationMode',
          placeholder: '请选择',
          select: {
            key: 'cooperationModeAttrSort'
          }
        },
        {
          col: 2,
          button: {
            title: '重置',
            click: () => {
              _this.clearForm()
            }
          }
        },
        {
          col: 2,
          button: {
            title: '搜索',
            type: 'primary',
            click: () => {
              _this.saveTableDatail()
            }
          }
        }
      ]
    ]
  }
}

export default SearchOpt
